home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9787 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  58 lines

  1. Newsgroups: comp.lang.c
  2. Path: phcoms4.seri.philips.nl!misf1!Pvestjen
  3. From: Pvestjen@ms.philips.nl (Patrick Vestjens)
  4. Subject: Re: confusion between putchar and printf
  5. Message-ID: <1996Mar13.075322.12898@ms.philips.nl>
  6. Sender: news@ms.philips.nl
  7. Organization: Philips Medical Systems, Best
  8. X-Newsreader: TIN [version 1.2 PL2]
  9. References: <4i1v2n$30o@news.azstarnet.com>
  10. Date: Wed, 13 Mar 1996 07:53:22 GMT
  11.  
  12. Howard Salmon (captarm@azstarnet.com) wrote:
  13. : K & R (section 1.5) states that "putchar(c) prints the contents of the 
  14. : integer variable c as a character, usually on the screen".
  15.  
  16. : Here's a small program that I wrote testing putchar.  Why doesn't it 
  17. : compile?
  18.  
  19. : #include <stdio.h>
  20. : # define A "hello world!"
  21.  
  22. : main()
  23. : {
  24. :     int c;
  25. :     c =  A;
  26. :     putchar(A);
  27. : }
  28.  
  29. : Thanks, 
  30. :         Howard Salmon (captarm@azstarnet.com)
  31.  
  32. After macro-expansion, your main looks like:
  33.  
  34. main()
  35. {
  36.   int c;
  37.   c = "hello world!";
  38.   putchar("hello world!");
  39. }
  40.  
  41. In other words, you're assigning a string constant to an integer
  42. variable and, in the second case, you're passing a string constant as to
  43. a function that expects an integer parameter. I'm not surprised that the
  44. compiler doesn't accept this code.
  45.  
  46. Don't know what you exactly want to do, but perhaps you should try
  47. printf, for example like this:
  48.  
  49. printf("%s", A);
  50.  
  51. which is expanded to:
  52.  
  53. printf("%s", "hello world!");
  54.  
  55. Success, Patrick.
  56.  
  57.  
  58.